﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;
using System.Windows.Media;
using Inspection.Helper;
using Inspection.Models;
using UserManager;

namespace Inspection
{
    internal class MainModel : PropertyChangedNotify
    {
        /// <summary>
        /// PLC的连接状态
        /// </summary>
        public bool TCPConnected
        {
            get { return _tcpConnected; }
            set { _tcpConnected = value; OnPropertyChanged(); }
        }
        private bool _tcpConnected = false;

        /// <summary>
        /// 是否自动模式下
        /// </summary>
        public UserTypes UserType
        {
            get { return _userType; }
            set { _userType = value; OnPropertyChanged(); }
        }
        private UserTypes _userType = UserTypes.None;

        /// <summary>
        /// 当前执行的Recipe
        /// </summary>
        public ProjectRecipe ExcuteRecipe
        {
            get { return _excuteRecipe; }
            set 
            {
                _excuteRecipe = value;
                OnPropertyChanged();
                if (value != null && _sysInitial != null)
                {
                    _sysInitial.ProjectFile = value.Name;
                }
            }
        }
        private ProjectRecipe _excuteRecipe = new ProjectRecipe();

        /// <summary>
        /// 当前执行的Recipe
        /// </summary>
        public SysInitialParame SysInitial
        {
            get { return _sysInitial; }
            set { _sysInitial = value; OnPropertyChanged(); }
        }
        private SysInitialParame _sysInitial = new SysInitialParame();
        
    }


    public class RunColorConv : MarkupExtension, IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value != null && value is bool && (bool)value ? System.Windows.Media.Brushes.Green : System.Windows.Media.Brushes.Black;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return this;
        }
    }
}
